﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SourFruit.player
{
    
    /// <summary>
    /// The entity that the player controls.
    /// </summary>
    public class Player 
    {
        public enum Status {standing, jumping}
        private Status currentStatus;
        private int width, height;
        private Texture2D stand, jump;
        public Vector2 Position;
        public Vector2 Velocity;        
        public readonly float WALKING_SPEED = 300;
        public readonly float JUMPING_SPEED = 700;
        public int Width { get { return width; } set { width = value; } }
        public int Height { get { return height; } set { height = value; } }

        public Rectangle BoundingBox
        {
            get
            {
                return new Rectangle(
                    (int)Position.X,
                    (int)Position.Y,
                    width,
                    height);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="position"></param>
        /// <param name="velocity"></param>
        /// <param name="_width"></param>
        /// <param name="_height"></param>
        /// <param name="_stand"></param>
        public Player(Vector2 position, Vector2 velocity, int _width, int _height, Texture2D _stand)
        {
            this.Position = position;
            this.Velocity = velocity;
            this.width = _width; this.height = _height;
            this.stand = _stand;
            this.currentStatus = Status.standing;
        }

        public void CreateEventPositionChanged()
        {
            if (PositionChanged != null)
                PositionChanged(this, (int)Position.X, (int)Position.Y, getPlayerTexture());
        }

        public void CreateEventPlayerDied()
        {
            if (PlayerDiedEvent != null)
                PlayerDiedEvent();
        }

        public Texture2D getPlayerTexture()
        {
            switch (currentStatus)
            {
                case Status.standing: return stand;
                default: return jump;
            }
        }

        public void setPlayerStatus(Status s)
        {
            currentStatus = s;
        }

        public void GotHit()
        {
            //here could be some if statements
            CreateEventPlayerDied();
        }



        /// <summary>  
        /// Handles the informing the receivers that the players position has changed.  
        /// </summary>  
        /// <param name="sender">The sender of the event.</param>  
        /// <param name="e">The EventArgs of the event.</param>  
        public delegate void PositionHandler(object sender, int x, int y, Texture2D texture);
        public event PositionHandler PositionChanged;

        /// <summary>  
        /// Handles the informing the receivers that the players position has changed.  
        /// </summary>  
        /// <param name="sender">The sender of the event.</param>  
        /// <param name="e">The EventArgs of the event.</param>  
        public delegate void PlayerDied();
        public event PlayerDied PlayerDiedEvent;

    }
}
